/*
 * Copyright (c) 2022 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include "spatial_client_test.h"

#include <iostream>
#include <chrono>
#include <thread>
#include <gtest/gtest.h>
#include <if_system_ability_manager.h>
#include <ipc_skeleton.h>
#include <string_ex.h>

using namespace testing::ext;
using namespace OHOS::Msdp;
using namespace OHOS;
using namespace std;

void SpatialClientTest::SetUpTestCase()
{
}

void SpatialClientTest::TearDownTestCase()
{
}

void SpatialClientTest::SetUp()
{
}

void SpatialClientTest::TearDown()
{
}

void SpatialClientTest::SpatialClientTestCallback::OnInnerOuterChanged(const InnerOuterResponse &ioRes)
{
}

void SpatialClientTest::SpatialClientTestCallback::OnDistanceChanged(const DistanceResponse &distanceRes)
{
}

void SpatialClientTest::SpatialClientTestCallback::OnAngleChanged(const AngleResponse &angleRes)
{
}

void SpatialClientTest::SpatialClientTestCallback::OnDirectionChanged(const DirectionResponse &directionRes)
{
    GTEST_LOG_(INFO) << "InnerOuter value: " << static_cast<int32_t>(directionRes.directionType);
}

void SpatialClientTest::SpatialClientTestCallback::OnExistChanged(const ExistResponse &existRes)
{
}

/*
 * @tc.name: SpatialClientTest_001
 * @tc.desc: Subscribe direction relation
 */
HWTEST_F(SpatialClientTest, SpatialClientTest_001, TestSize.Level0)
{
    GTEST_LOG_(INFO) << "SpatialClientTest_001 start test";
    auto& spatialMgrClient = SpatialAwarenessMgrClient::GetInstance();
    sptr<ISpatialLocationCallback> cb1 = new SpatialClientTestCallback();

    SpatialLocationMode mode = SpatialLocationMode::MODE_DIRECTION;
    SpatialDeviceInfo info("1", "7001005458323933328a519c2ead3800", SpatialDeviceType::DEVICE_TYPE_UNKNOWN);
    spatialMgrClient.SubscribeSpatialLocationRelationship(mode, info, cb1);
    sleep(WAIT_TIME);
    spatialMgrClient.UnSubscribeSpatialLocationRelationship(mode, info, cb1);
    GTEST_LOG_(INFO) << "SpatialClientTest_001 end";
}

/*
 * @tc.name: SpatialClientTest_002
 * @tc.desc: Subscribe distance relation
 */
HWTEST_F(SpatialClientTest, SpatialClientTest_002, TestSize.Level0)
{
    GTEST_LOG_(INFO) << "SpatialClientTest_001 start test";
    auto& spatialMgrClient = SpatialAwarenessMgrClient::GetInstance();
    sptr<ISpatialLocationCallback> cb1 = new SpatialClientTestCallback();

    SpatialLocationMode mode = SpatialLocationMode::MODE_DISTANCE;
    SpatialDeviceInfo info("1", "7001005458323933328a519c2ead3800", SpatialDeviceType::DEVICE_TYPE_UNKNOWN);
    spatialMgrClient.SubscribeSpatialLocationRelationship(mode, info, cb1);
    sleep(WAIT_TIME);

    spatialMgrClient.UnSubscribeSpatialLocationRelationship(mode, info, cb1);
    GTEST_LOG_(INFO) << "SpatialClientTest_001 end";
}

/*
 * @tc.name: SpatialClientTest_003
 * @tc.desc: Subscribe angle relation
 */
HWTEST_F(SpatialClientTest, SpatialClientTest_003, TestSize.Level0)
{
    GTEST_LOG_(INFO) << "SpatialClientTest_001 start test";
    auto& spatialMgrClient = SpatialAwarenessMgrClient::GetInstance();
    sptr<ISpatialLocationCallback> cb1 = new SpatialClientTestCallback();

    SpatialLocationMode mode = SpatialLocationMode::MODE_ANGLE;
    SpatialDeviceInfo info("1", "7001005458323933328a519c2ead3800", SpatialDeviceType::DEVICE_TYPE_UNKNOWN);
    spatialMgrClient.SubscribeSpatialLocationRelationship(mode, info, cb1);
    sleep(WAIT_TIME);

    spatialMgrClient.UnSubscribeSpatialLocationRelationship(mode, info, cb1);
    GTEST_LOG_(INFO) << "SpatialClientTest_001 end";
}

/*
 * @tc.name: SpatialClientTest_004
 * @tc.desc: Subscribe inner and outer relation
 */
HWTEST_F(SpatialClientTest, SpatialClientTest_004, TestSize.Level0)
{
    GTEST_LOG_(INFO) << "SpatialClientTest_001 start test";
    auto& spatialMgrClient = SpatialAwarenessMgrClient::GetInstance();
    sptr<ISpatialLocationCallback> cb1 = new SpatialClientTestCallback();

    SpatialLocationMode mode = SpatialLocationMode::MODE_INNER_OUTER;
    SpatialDeviceInfo info("1", "7001005458323933328a519c2ead3800", SpatialDeviceType::DEVICE_TYPE_UNKNOWN);
    spatialMgrClient.SubscribeSpatialLocationRelationship(mode, info, cb1);
    sleep(WAIT_TIME);

    spatialMgrClient.UnSubscribeSpatialLocationRelationship(mode, info, cb1);
    GTEST_LOG_(INFO) << "SpatialClientTest_001 end";
}

/*
 * @tc.name: SpatialClientTest_005
 * @tc.desc: Subscribe relation
 */
HWTEST_F(SpatialClientTest, SpatialClientTest_005, TestSize.Level0)
{
    GTEST_LOG_(INFO) << "SpatialClientTest_001 start test";
    auto& spatialMgrClient = SpatialAwarenessMgrClient::GetInstance();
    sptr<ISpatialLocationCallback> cb1 = new SpatialClientTestCallback();

    SpatialLocationMode mode = SpatialLocationMode::MODE_EXIST;
    SpatialDeviceInfo info("1", "7001005458323933328a519c2ead3800", SpatialDeviceType::DEVICE_TYPE_UNKNOWN);
    spatialMgrClient.SubscribeSpatialLocationRelationship(mode, info, cb1);
    sleep(WAIT_TIME);

    spatialMgrClient.UnSubscribeSpatialLocationRelationship(mode, info, cb1);
    GTEST_LOG_(INFO) << "SpatialClientTest_001 end";
}